Home > Java Programming > Inner Classes > Questions and Answers
01. |
What is the output for the below code ? public class Outer { private int a = 7; class Inner { public void displayValue() { System.out.println("Value of a is " + a); } } } public class Test { public static void main(String... args) throws Exception { Outer mo = new Outer(); Outer.Inner inner = mo.new Inner(); inner.displayValue(); } } | |||||||||||
|
02. | Modifiers Applied to Inner Classes is ________________? | |||||||||||||||
|
03. |
What is the output for the below code ? class Outer { private String x = "Outer variable"; void doStuff() { String z = "local variable"; class Inner { public void seeOuter() { System.out.println("Outer x is " + x); System.out.println("Local variable z is " + z); } } } } | |||||||||||
|
04. |
What is the output for the below code ? public class Tech { public void tech() { System.out.println("Tech"); } } public class Atech { Tech a = new Tech() { public void tech() { System.out.println("anonymous tech"); } }; public void dothis() { a.tech(); } public static void main(String... args){ Atech atech = new Atech(); atech.dothis(); } } | |||||||||||
|
05. |
What is the output for the below code ? public interface Ianimal { public void eat(); } public class Tiger { Ianimal c = new Ianimal() { public void eat() { System.out.println("Tiger eat non-veg"); } }; public void doit(){ c.eat(); } public static void main(String... args){ Tiger t = new Tiger(); t.doit(); } } | |||||||||||
|
06. |
Is the bellow code compile without error? public class ThreadTest { Runnable r = new Runnable() { public void run() { } }; } | |||||||||||
|
07. |
What is the true about the bellow code class Outer { static class Inner { } } | |||||||||||
|
08. |
What is the output for the below code ? class Outer { static class Inner { void go() { System.out.println("Inner.go"); } } } public class Test { static class Inner1 { void go() { System.out.println("Inner1.go"); } } public static void main(String... args) throws Exception { Outer.Inner bn = new Outer.Inner(); bn.go(); Inner1 in = new Inner1(); in.go(); } } | |||||||||||
|
09. | Which are true about an anonymous inner class? | |||||||||||
|
10. |
What will be the result of compiling and run the following code: public class Test { public static void main(String... args) throws Exception { Object o = new Object() { public boolean equals(Object obj) { return true; } } System.out.println(o.equals("test")); } } | |||||||||||
|